
#ifndef MAILER_H_
#define MAILER_H_

#include <vector>
#include <string>
#include <pthread.h>
#include "Mailbox.h"
#include "Scheduler.h"
#include "Graph.h"
#include "Mutexes.h"

using namespace std;

class Mailer {

public:

//	static pthread_mutex_t 		_mailer_inbox_empty_lock;
//	static pthread_cond_t 		_mailer_inbox_empty_cond;

	Mailer(Mailbox* shell_inbox);
	virtual ~Mailer();
	bool creat_net(string filename);
	void put_in_inbox(Message* message);
	void start(int schedule_num);
	void handle_messages();
	void handle_scheduling();
	void send_message(Mailbox* receiver_mailbox, Message* message);
    Mailbox *getMailer_inbox() const
    {
        return _mailer_inbox;
    }

    Scheduler *getScheduler() const
    {
        return _scheduler;
    }

    Graph *getGraph() const
    {
        return _graph;
    }

private:
	Graph*				_graph;
	int					_buffer_size;
	Mailbox*			_mailer_inbox;
	Mailbox*			_shell_inbox;
	Scheduler*			_scheduler;

	Worker* get_worker(int id);
	void handle_single_message();
};

#endif /* MAILER_H_ */
